package com.rfid.emergencywarehouse.presenter;

import android.text.TextUtils;

import com.rfid.emergencywarehouse.entity.BarcodeInfo;
import com.rfid.emergencywarehouse.net.NetApi;
import com.rfid.emergencywarehouse.net.entity.PandianRes;
import com.rfid.emergencywarehouse.view.IPandianvView;

import java.util.ArrayList;
import java.util.List;

public class PanDianPresenter extends ReadTagPresenter<IPandianvView> {



    public void pandian(String shelf,List<String> barcodes) {
        mExcutor.execute(new Runnable() {
            @Override
            public void run() {
                String msg = null;
                List<BarcodeInfo> infos = new ArrayList<>();
                try {
                    PandianRes res = NetApi.INSTANCE.pandian(shelf,barcodes);
                    List<PandianRes.DataBean>  beans = res.getData();
                    for (PandianRes.DataBean bean:beans){
                        BarcodeInfo info = new BarcodeInfo();
                        info.setDisplayName(bean.getDisplayName());
                        info.setSkuModel(bean.getSkuModel());
                        info.setMaterialName(bean.getMaterialName());
                        info.setMaterialType(bean.getMaterialType());
                        info.setBarcode(bean.getBarCode());
                        info.setDiffCount(bean.getDiffCount());
                        infos.add(info);
                    }
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (mView != null) {
                                mView.onPandianResult(infos);
                            }
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    msg = e.getMessage();
                }
                if (TextUtils.isEmpty(msg)) {
                    return;
                }
                String finalMsg = msg;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (mView != null) {
                            mView.onFailMsg(finalMsg);
                        }
                    }
                });
            }
        });
    }
}
